package com.itheima.demo03;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapClass01 {
    public static void main(String[] args) {
        HashMap<String, Student> hs = new HashMap<>();
        Student stu1 = new Student("zhangsan", 85, 86, 87);
        Student stu2 = new Student("xiaomei", 81, 26, 37);
        Student stu3 = new Student("juanhuang", 75, 56, 97);
        Student stu4 = new Student("xiaojuan", 84, 76, 47);

        hs.put("heima001", stu1);
        hs.put("heima002", stu2);
        hs.put("heima003", stu3);
        hs.put("heima004", stu4);
        print(hs);

        System.out.println("---------------------------------------");

        //method1(hs);
        //method2(hs);
        //method3(hs);
        //method4(hs);
        //method5(hs);
        //method6(hs);

        /*Set<String> strings = hs.keySet();
        for (String string : strings) {
//            System.out.println(string);
            Student student = hs.get(string);
            System.out.println(string + student);
        }*/

        /*Collection<Student> values = hs.values();
        for (Student value : values) {
            System.out.println(value);
        }*/

        Set<Map.Entry<String, Student>> entries = hs.entrySet();
        for (Map.Entry<String, Student> entry : entries) {
            String key = entry.getKey();
            Student value = entry.getValue();
            System.out.println(key + "----" + value);
        }
    }

    private static void method6(HashMap<String, Student> hs) {
        int size = hs.size();
        System.out.println(size);
    }

    private static void method5(HashMap<String, Student> hs) {
        boolean result1 = hs.isEmpty();
        method1(hs);
        boolean result2 = hs.isEmpty();
        print1(result1,result2);
    }

    private static void method4(HashMap<String, Student> hs) {
        boolean result1 = hs.containsValue(hs);
        boolean result2 = hs.containsValue(hs);
        print1(result1, result2);
    }

    private static void method3(HashMap<String, Student> hs) {
        boolean result1 = hs.containsKey("heima005");
        boolean result2 = hs.containsKey("heima002");
        print1(result1, result2);
    }

    private static void print1(boolean result1, boolean result2) {
        System.out.println(result1);
        System.out.println(result2);
    }

    private static void method2(HashMap<String, Student> hs) {
        Student re = hs.remove("heima001");
        print(hs);
    }

    private static void print(HashMap<String, Student> hs) {
        hs.forEach((o, i) -> {
            System.out.println(o + "------" + i);
        });
    }

    private static void method1(HashMap<String, Student> hs) {
        hs.clear();
        print(hs);
    }
}
